/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.user;

import java.util.List;
import queenb.net.entitybean.B670;
import queenb.web.controller.QueenbController;
import queenb.web.store.B670Store;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class B670Controller extends QueenbController{
    private B670Store b670Store;
    
    private int pb670;
    private String bv671;
    private String bv672;
    private boolean flag;
    
    public B670Controller()
    {
        b670Store = new B670Store();
        Object pb670Object = getRequest().getParameter("pb670");
        if(getRequest().getParameter("action") != null)
        {
            String action = getRequest().getParameter("action");
            if(action.equals("add"))
            {
                flag = true;
            }
            if(action.equals("edit"))
            {
                flag = false;
                this.pb670 = Util.parseInt(pb670Object);
                getListK250DetailEdit(pb670);
            }
        }
    }
    
    public List<B670> getListB670All()
    {
        try{
            List<B670> listB670 = b670Store.getListB670All(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            return listB670;
        }catch(Exception ex)
        {
            return null;
        }
    }
    
    public void getListK250DetailEdit(int pb670i)
    {
        this.pb670 = pb670i;
        try{
            List<B670> listB670ByID = getListB670All();
            if(listB670ByID.size() > 0)
            {
                for(int i = 0; i < listB670ByID.size(); i++)
                {
                    if(listB670ByID.get(i).getPb670() == pb670)
                    {
                        this.bv671 = listB670ByID.get(i).getBv671();
                        this.bv672 = listB670ByID.get(i).getBv672();
                        break;
                    }
                }
            }
        }catch(Exception ex)
        {
              System.out.println("ERROR : " + ex.getMessage());
        }
    }
    
    public void updateB670()
    {
        if(flag == true)
        {
            int count = b670Store.updateB670(pb670, bv671, bv672,getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }else{
            int count = b670Store.updateB670(pb670, bv671, bv672,getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }
        sendRedirectUrlTab("setting.jsp?tab=header4&"+Util.convertMD5(getRequest().getRequestURI()));
    }
    
     public int deleteB670(int id)
    {
        if(id != 0)
        {
            int rows = b670Store.deleteB670(id, getLogin().getUserName());
            return rows;
        }else
        {
            return 0;
        }
            
    }

    /**
     * @return the pb670
     */
    public int getPb670() {
        return pb670;
    }

    /**
     * @param pb670 the pb670 to set
     */
    public void setPb670(int pb670) {
        this.pb670 = pb670;
    }

    /**
     * @return the bv671
     */
    public String getBv671() {
        return bv671;
    }

    /**
     * @param bv671 the bv671 to set
     */
    public void setBv671(String bv671) {
        this.bv671 = bv671;
    }

    /**
     * @return the bv672
     */
    public String getBv672() {
        return bv672;
    }

    /**
     * @param bv672 the bv672 to set
     */
    public void setBv672(String bv672) {
        this.bv672 = bv672;
    }
}
